package com.henry.imkit

import com.blankj.utilcode.util.TimeUtils
import java.io.DataInput
import java.util.*

// 图片格式
const val IM_IMAGE_FORMAT_JPG    = 0x1  // JPG格式
const val IM_IMAGE_FORMAT_GIF    = 0x2  // GIF格式
const val IM_IMAGE_FORMAT_PNG    = 0x3  // PNG格式
const val IM_IMAGE_FORMAT_BMP    = 0x4  // BMP格式
const val IM_IMAGE_FORMAT_UNKNOWN = 0xff // 未知格式

// 图片类型
const val IM_IMAGE_TYPE_ORIGIN = 0x1  // 原图
const val IM_IMAGE_TYPE_LARGE  = 0x2  // 大图
const val IM_IMAGE_TYPE_THUMB  = 0x3  // 缩略图

// 消息类型
const val IM_ELEM_SYSTEM = "TIMSystemElem"
const val IM_ELEM_REVOKE = "TIMRevokeElem"
const val IM_ELEM_TEXT = "TIMTextElem"
const val IM_ELEM_IMAGE = "TIMImageElem"
const val IM_ELEM_FILE = "TIMFileElem"
const val IM_ELEM_SOUND = "TIMSoundElem"
const val IM_ELEM_CUSTOM = "TIMCustomElem"
const val IM_ELEM_FACE = "TIMFaceElem"
const val IM_ELEM_ONIS_CASE = "TIMONISCaseElem"

open class IMElem {
    var type: String? = ""
}

class IMSystemElem : IMElem() {
    var etype: String = ""
    var etypename: String = ""
    var text: String = ""
    init {
        type = IM_ELEM_SYSTEM
    }
}

class IMTextElem : IMElem() {
    var text: String = ""
    init {
        type = IM_ELEM_TEXT
    }
}

class IMRevokeElem : IMElem() {
    var douserid: String? = ""
    var text: String = ""
    init {
        type = IM_ELEM_REVOKE
    }
}

class IMImage {
    var url: String = ""
    var type: Int = IM_IMAGE_TYPE_ORIGIN
    var size: Int = 0
    var width: Int = 0
    var height: Int = 0
}

class IMImageElem : IMElem() {
    var imageformat: Int = IM_IMAGE_FORMAT_UNKNOWN
    var imagearray: List<IMImage>? = null
    init {
        type = IM_ELEM_IMAGE
    }
}

class IMSoundElem : IMElem() {
    var url: String = ""
    // 毫秒
    var duration: Int = 0
    init {
        type = IM_ELEM_SOUND
    }
}

class IMFileElem : IMElem() {
    var path: String = ""
    var data: DataInput? = null
    var fileSize: Int = 0
    var filename: String = ""
    init {
        type = IM_ELEM_FILE
    }
}

class IMCustomElem : IMElem() {
    var data: String = ""
    var customtype: Int = 0
    init {
        type = IM_ELEM_CUSTOM
    }
}

class IMONISCaseElem : IMElem() {
    var data: String = ""
    var uid: String = ""
    var uname: String = ""
    var overtime: String = ""
    var techvisitid: String = ""
    var mrname: String = ""
    var content: String = ""
    var url: String = ""
    init {
        type = IM_ELEM_ONIS_CASE
    }
}

class IMSendMessage {
    var eamtimestamp: Long = 0
    var eamrandom: String? = null
    var eamessagecontent: List<Any>? = null
    init {
        eamtimestamp = TimeUtils.getNowMills()
        eamrandom = UUID.randomUUID().toString()
    }
}

class IMMessage {
    var eamid: String? = null
    var eamtimestamp: Long = 0
    var eamfromid: String? = null
    var eamfromname: String? = null
    var eamfromheadportrait: String? = null
    var eamtoid: String? = null
    var eamseq: String? = null
    var eamrandom: String? = null
    var eamessagetype: String? = null
    var eamreadlogtime: String? = null  // 已读记录时间，用于语音等点击
    var eamessagecontent: List<IMElem>? = null

    init {
        eamtimestamp = TimeUtils.getNowMills()
        eamrandom = UUID.randomUUID().toString()
    }

    fun addElem(elem: IMElem) {
        val contents = mutableListOf<IMElem>()
        eamessagecontent?.let { contents.addAll(it) }
        contents.add(elem)
        eamessagecontent = contents
    }

}

